package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.NoticeMapper;
import com.ruoyi.system.domain.Notice;
import com.ruoyi.system.service.INoticeService;

/**
 * 消息通知Service业务层处理
 * 
 * @author lfm
 * @date 2024-08-17
 */
@Service
public class NoticeServiceImpl implements INoticeService 
{
    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * 查询消息通知
     * 
     * @param id 消息通知主键
     * @return 消息通知
     */
    @Override
    public Notice selectNoticeById(Long id)
    {
        return noticeMapper.selectNoticeById(id);
    }

    /**
     * 查询消息通知列表
     * 
     * @param notice 消息通知
     * @return 消息通知
     */
    @Override
    public List<Notice> selectNoticeList(Notice notice)
    {
        return noticeMapper.selectNoticeList(notice);
    }

    @Override
    public List<Notice> selectNoticeLists(Long userId, Integer targetType) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("targetType", targetType);
        List<Notice> lists = noticeMapper.selectNoticeLists(map);
        return lists;
    }

    /**
     * 新增消息通知
     * 
     * @param notice 消息通知
     * @return 结果
     */
    @Override
    public int insertNotice(Notice notice)
    {
        if(notice.getTypeId() == 1){
            notice.setMessage("您的订单："+notice.getKeywords()+"，已从厂家发货。");
            notice.setCreateTime(new Date());
        } else if (notice.getTypeId() == 2) {
//            notice.setMessage(message.get("userName")+"在"+ notice.getCreateTime()+" 回复了您的一条评论信息。");
//            notice.setCreateTime(new Date());
        }else if(notice.getTypeId() == 3){
            notice.setMessage("您的订单："+notice.getKeywords()+"，已确认收货。如果非本人操作请尽快联系客服！");
            notice.setCreateTime(new Date());
        } else if (notice.getTypeId() == 4) {
//            notice.setMessage("您的订单："+keywords+"从"+message.get("fromArea")+"到"+message.get("toArea")+"的货物订单已经支付成功，请注意核实。");
//            notice.setCreateTime(new Date());
        }
        return noticeMapper.insertNotice(notice);
    }

    /**
     * 修改消息通知
     * 
     * @param notice 消息通知
     * @return 结果
     */
    @Override
    public int updateNotice(Notice notice)
    {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 批量删除消息通知
     * 
     * @param ids 需要删除的消息通知主键
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] ids)
    {
        return noticeMapper.deleteNoticeByIds(ids);
    }

    /**
     * 删除消息通知信息
     * 
     * @param id 消息通知主键
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long id)
    {
        return noticeMapper.deleteNoticeById(id);
    }
}
